package com.looookme.shaozhuo.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

/**
 * Created by Shaozhuo on 2015/9/8.
 */
public class ActivityBundle extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();
    }

    private void initView() {
        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);

        final EditText editText = new EditText(this);
        editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        editText.setHint("Please input some data");
        editText.setTextSize(24);
        ll.addView(editText);

        Button btn = new Button(this);
        btn.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        btn.setText("Start Activity");
        ll.addView(btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!"".equals(editText.getText().toString())) {
                    Intent intent = new Intent(ActivityBundle.this, ActivityBundle_2.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("KEY", editText.getText().toString());
                    intent.putExtras(bundle);
                    startActivity(intent);
                } else {
                    Toast.makeText(ActivityBundle.this, "Edittext is Empty", Toast.LENGTH_SHORT).show();
                }
            }
        });

        setContentView(ll);
    }
}
